package com.kwan80gmail.flextime.models;

import android.content.ContentValues;
import android.content.Context;

import com.google.android.gms.location.Geofence;

import java.util.ArrayList;

/**
 * Created by Kevin on 2015-03-10.
 */
public class MainModel
{
    private ArrayList<Place> places;
    private GpsTracker gpsTracker;

    private SqlLiteHelper database;



    public MainModel()
    {

    }

    public synchronized SqlLiteHelper getDatabase(Context context)
    {
        if(database == null)
        {
            database = new SqlLiteHelper(context);
        }

        return database;
    }


    public synchronized GpsTracker getGpsTracker(Context context)
    {
        if(gpsTracker == null)
        {
            gpsTracker = new GpsTracker(context);
        }
        return gpsTracker;
    }


    public void addNewLocation(int locationId, String name, double latitude, double longitude, int radius)
    {
        Place place = new Place(locationId, name, latitude, longitude, radius);
        places.add(place);
    }

    public double getLatitude(String name)
    {
        for (Place place : places)
        {
            if (name.equals(place.getName()))
            {
                return place.getLatitude();
            }
        }

        return 0;
    }

    public double getLongitude(String name)
    {
        for (Place place : places)
        {
            if (name.equals(place.getName()))
            {
                return place.getLongitude();
            }
        }

        return 0;
    }
}
